$(function(){			
	//set default object
	$('#loader-menu-left').hide();	
	$('#loader-content').hide();	
	
	//set variable or inisialisasi
	var BASE_URL='<?php echo base_url();?>';	
	var username='<?php echo $this->session->userdata("username");?>';
	var userlevel='<?php echo $this->session->userdata("level");?>';			
	var menu_id ='<?php echo $this->session->userdata("menu");?>';	
        var content_type='<?php echo $this->session->userdata("content_type");?>';	
        var button=new Array();        
	var headerForm=setHeaderForm();
	var curr_menu;
	
	if(menu_id==''){
		curr_menu =0;		
	}else{
		curr_menu = menu_id;
	}
			
	
	//set function
	function currentMenu(id,type){									
		getMenu(id);		
		return false;		
	}		
        
	currentMenu(curr_menu);	
	
        //set button
        function setButton(){
            button=['Create','Update','Delete'];
            var buttonList='';
            for(var i=0;i<button.length;i++){
                buttonList+='<a href="#" class="btn" id="'+button[i]+'">'+button[i]+'</a>';
                $('button[i]').appendTo('.headerForm');
            }            
            return buttonList;
        }
        
        // set header panel
	function setHeaderForm(){                
		var me="<div class='headerForm'></div>";	                
		return me;
	}
	
	// alert message location themes_top_v
	
	$('#myMsg').click(function(){
		$(this).animate({'left':'1000','top':'-100'},'fast');
	});
	
	function showAlert(type,str){
		var el=$('#myMsg');
		var w=str.length +20;
		var t=el.height+20;
		
		el.hide();
		switch(type){
			case 0://info
				el.empty().addClass('msgInfo');
			break;
			case 1://notification
				el.empty().addClass('msgNotif');
			break;
			case 2://error
				el.empty().addClass('msgError');
			break;
		}
		el.append(str).css({'width':'w','height':'t'}).show().animate({'left':25,'top':25},'fast');
	}
	
	function getMenu(id,type){								            
            if(type=='json'){
                content_type='json';
            }else{
                content_type='html';
            }
            
		$.ajax({
			type:'GET',
			url:BASE_URL+'ajax/getMenu/'+id+'/'+type,								
                        dataType:content_type,
			beforeSend:function(){
				$('#loader-content').empty().append('<img src="<?php echo base_url();?>assets/img/loader.gif"> Mohon Menunggu ....');
				$('#loader-content').show();	
			},			
			success:function(data){							
				$('#loader-content').hide();				
				if(type=='html'){
                        $('#main-content').empty().html(headerForm+data);
                }else if(type=='json'){                                                                        
                        $('#main-content').empty().html(headerForm);                                                                                                                            
				}
			}
		});		
	}		
		
	//set event
	$('.header_menu').click(function(el){ //menu atas		
		menu_id=$(this).attr('id');
                type=$(this).attr('type');
		getMenu(menu_id,type);									
	});
	$('.left_menu').click(function(el){//menu kiri				
		menu_id=$(this).attr('id');					
                type=$(this).attr('type');
		getMenu(menu_id,type);			
	});	
	
	$('.alert-heading').click(function(){//link u/ redirect bila user salah password
		window.location.href='<?php echo base_url();?>login';
	});
					
})